﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 基于WPF的电缆采样数据分析系统.Models.Enums;

namespace 基于WPF的电缆采样数据分析系统.Models.Dbs.DbService
{
    public class UpdateWavListDAOService
    {
        /// <summary>
        /// 单例模型
        /// </summary>
        public static UpdateWavListDAOService Instance = new UpdateWavListDAOService(App.GetService<TDRDbContext>());

        /// <summary>
        /// 数据库上下文
        /// </summary>
        private readonly TDRDbContext db;

        /// <summary>
        /// 构造器
        /// </summary>
        /// <param name="_db"></param>
        public UpdateWavListDAOService(TDRDbContext _db)
        {
            db = _db;
        }


        /// <summary>
        /// 添加导出波形信息
        /// </summary>
        /// <param name="projectDataInfoDAO"></param>
        /// <returns></returns>
        public RetResult AddUpdateWavListDAO(UpdateWavListDAO updateWavListDAO)
        {
            try
            {
                db.UpdateWavListDAOs.Add(updateWavListDAO);

                int rows = db.SaveChanges();

                if (rows > 0)
                {
                    return RetResult.Success;
                }

                return RetResult.Fail;
            }
            catch (Exception ex)
            {
                return RetResult.Fail;
            }
        }

        /// <summary>
        /// 获取所有的导出波形信息
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<UpdateWavListDAO> GetUpdateWavListDAOList()
        {
            try
            {

                ObservableCollection<UpdateWavListDAO> updateWavListDAOs = new ObservableCollection<UpdateWavListDAO>(db.UpdateWavListDAOs);

                if (updateWavListDAOs.Count > 0)
                {
                    return updateWavListDAOs;
                }

                return null;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
